package var.syntax;

import tr.edu.ege.kipler.syntax.KModality;
import tr.edu.ege.kipler.syntax.ModalOperator;
import tr.edu.ege.kipler.syntax.TypedModality;

/**
 * The modal operators
 */
public class BeliefOperator extends ModalOperator implements KModality,
		TypedModality {
	private static final String BOX_BELIEF = "[B]";

	private static final String DIAMOND_BELIEF = "<B>";

	public static BeliefOperator boxBelief(String agent) {
		BeliefOperator op = new BeliefOperator();
		op.setModality(BOX_BELIEF);
		op.setAgent(agent);
		return op;
	}

	public static BeliefOperator diamondBelief(String agent) {
		BeliefOperator op = new BeliefOperator();
		op.setModality(DIAMOND_BELIEF);
		op.setAgent(agent);
		return op;
	}

	public String getAgent() {
		return (String) getParameter("agent");
	}

	private void setAgent(String agent) {
		setParameter("agent", agent);
	}

	private String getModality() {
		return (String) getParameter("modality");
	}

	private void setModality(String modality) {
		setParameter("modality", modality);
	}

	public ModalOperator getDual() {
		ModalOperator result;
		if (getModality() == BOX_BELIEF) {
			result = diamondBelief(getAgent());
		} else {
			result = boxBelief(getAgent());
		}
		return result;
	}

	public String getRelation() {
		return "B-" + getAgent();
	}

	public ModalOperator copy() {
		BeliefOperator result = new BeliefOperator();
		result.setAgent(getAgent());
		result.setModality(getModality());
		return result;
	}

	public boolean isNecessiate() {
		return getModality().equals(BOX_BELIEF);
	}

	public String getType() {
		return "belief";
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		char var;
		if (isNecessiate()) {
			var = '[';
		} else {
			var = '<';
		}
		buffer.append(var);
		buffer.append("B, \"");
		buffer.append(getAgent());
		buffer.append("\"");
		if (isNecessiate()) {
			var = ']';
		} else {
			var = '>';
		}
		buffer.append(var);
		return buffer.toString();
	}
}